package com.city.service.party.impl;

import com.city.domain.party.PartyBranch;
import com.city.repository.party.PartyBranchRepository;
import com.city.service.party.PartyBranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PartyBranchServiceImpl implements PartyBranchService {
    @Autowired
    private PartyBranchRepository partyBranchRepository;


    @Override
    public void save(PartyBranch partyBranch) {
        partyBranchRepository.save(partyBranch);
    }

    @Override
    public List<PartyBranch> findAll(Integer page, Integer limit) {
        return partyBranchRepository.findAllPartyBranch((page-1)*limit,limit);
    }

    @Override
    public long count() {
        return partyBranchRepository.count();
    }

    @Override
    public PartyBranch findById(int id) {
        return partyBranchRepository.findOne(id);
    }

    @Override
    public List<PartyBranch> findAllPartyBranch() {
        return partyBranchRepository.findAll();
    }

    @Override
    public void deleteById(int id) {
        partyBranchRepository.delete(id);
    }

    @Override
    public List<PartyBranch> findLikeName(String branchName, Integer page, Integer limit) {
        return partyBranchRepository.findAllByNameAndPage(branchName,(page-1)*limit,limit);
    }

    @Override
    public long countName(String branchName) {
        return partyBranchRepository.countName(branchName);
    }


}
